package lvm

import "context"

// LVRemove 逻辑卷删除
func LVRemove(ctx context.Context, vgName, lvName string) (err error) {
	lv := getLV(ctx, vgName, lvName)
	if lv == nil {
		err = ErrNotFound
		return
	}

	vg := getVG(ctx, lv.VGName)
	if vg == nil {
		err = ErrNotFound
		return
	}

	_, err = execCommand(ctx, "lvremove", "-y", lv.Path)
	if err != nil {
		return
	}
	lv = getLV(ctx, vgName, lvName)
	if lv != nil {
		err = ErrCommand
	}
	return
}
